package cn.wolfcode.shop.service.impl;

import cn.wolfcode.shop.config.WebSocketServer;
import cn.wolfcode.shop.result.CodeMsg;
import cn.wolfcode.shop.service.IWebSocketService;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Service;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

@Service
public class WebSocketServiceImpl implements IWebSocketService {
    @Override
    public boolean sendWebsocketMsg(String uuid, String codeMsg) {
        ConcurrentHashMap<String, WebSocketServer> clients = WebSocketServer.clients;
        WebSocketServer webSocketServer = clients.get(uuid);
        try {
            webSocketServer.getSession().getBasicRemote().sendText(codeMsg);
            return true;
        } catch (Exception e) {
            e.printStackTrace();

            return false;
        }
    }
}
